home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Browsers, Managers & Extensions
/
Mozilla Geode 1.5
/
geode-latest.xpi
/
content
/
injected.js
< prev
next >
Wrap
Text File
|
2008-10-06
|
3KB
|
116 lines
window.navigator.geolocation = {
/* ----- nsIDOMGeoGeolocation ----- */
get lastPosition() {
return this._lastPosition;
},
getCurrentPosition : function(successCallback, errorCallback, options) {
if (!successCallback)
throw "successCallback argument to getCurrentPosition is required";
// "options" is ignored
var ID = this._geoGetterSerial++;
this._geoGetters[ID] = [successCallback, errorCallback];
this._geoGetterCount++;
this._sendRequest("getPosition");
},
watchPosition : function(successCallback, errorCallback, options) {
if (!successCallback)
throw "successCallback argument to watchPosition is required";
// "options" is ignored
var ID = this._geoWatcherSerial++;
this._geoWatchers[ID] = [successCallback, errorCallback];
// First watcher starts the ball rolling..
if (this._geoWatcherCount == 0) {
var self = this;
this._intervalID = setInterval(
function() {
self._sendRequest("watchPosition");
}, 30 * 1000);
this._sendRequest("watchPosition");
}
this._geoWatcherCount++;
return ID;
},
clearWatch : function (aID) {
if (!(aID in this._geoWatchers))
throw "invalid ID";
delete this._geoWatchers[aID];
this._geoWatcherCount--;
if (this._geoWatcherCount == 0) {
clearInterval(this._intervalID);
//this._sendRequest("stopWatchPosition");
}
},
/* ----- end of public API ----- */
_lastPosition : null,
_geoGetters: {},
_geoGetterCount : 0,
_geoGetterSerial : 0,
_geoWatchers : {},
_geoWatcherCount : 0,
_geoWatcherSerial : 0,
_intervalID : null,
_sendRequest : function (type, ID) {
// window.addEventListener("geoLocationReply", this._eventListener, false);
var event = document.createEvent("Events");
event.initEvent("x-geode-locationRequest-" + type, true, true);
window.dispatchEvent(event);
},
_notifyListeners : function(aPosition) {
var callbacks;
if ("latitude" in aPosition)
this._lastPosition = aPosition;
// The getCurrentPosition callbacks are one-shot, so call and remove.
for each (callbacks in this._geoGetters) {
// Use the error handler if the "position" is really an error.
var callback;
if ("latitude" in aPosition)
callback = callbacks[0];
else
callback = callbacks[1];
try {
callback(aPosition);
} catch (e) {}
}
this._geoGetters = {};
this._geoGetterCount = 0;
for each (callbacks in this._geoWatchers) {
// Use the error handler if the "position" is really an error.
var callback;
if ("latitude" in aPosition)
callback = callbacks[0];
else
callback = callbacks[1];
try {
callback(aPosition);
} catch (e) {}
}
}
};